// ml:run = time -p $bin < input > output
#include <cstdio>
#include <cmath>

using ll = long long;
ll a, b;

ll calc(ll x)
{
    ll c = std::round(std::cbrt(x));
    if (c * c * c == x) return c;
    return -1;
}

int main()
{
    ll n;
    scanf("%I64d", &n);
    for (ll i = 0; i < n; i++) {
        scanf("%I64d", &a);
        scanf("%I64d", &b);
        ll c = calc(a * b);
        if (c == -1) {
            printf("NO\n");
            continue;
        }
        if (c == 0) {
            if (!a && !b)
                printf("YES\n");
            else
                printf("NO\n");
            continue;
        }
        ll k1 = b / c;
        ll k2 = a / c;
        if (k1 * k2 * k2 != a || k1 * k1 * k2 != b) {
            printf("NO\n");
            continue;
        }
        printf("YES\n");
    }
}

